<?php
ob_start();
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
session_start();
require_once("configuration.php");
require_once("includes/db/constant.php");
require_once("includes/db/dbsetup.php");
define("TEMPLATE_NAME", 'blue/');

require_once("includes/MySmarty.class.php");
require_once('localization.php');
require_once('localization_func.php');
require_once("admin/includes/util.php");
require_once ("Zend/Loader.php");

require_once("module/controller/config.class.php");
require_once("module/controller/document.class.php");

require_once("module/model/FIN_categoryBean.class.php");
//require_once("module/model/FIN_productBean.class.php");
require_once("module/model/FIN_newsBean.class.php");
//require_once("module/model/FIN_pageBean.class.php");
require_once("module/model/FIN_requestBean.class.php");
require_once("module/model/FIN_CountryBean.class.php");
require_once("module/controller/Paging.class.php");

include_once("module/controller/category.class.php");

$smarty->assign("TEMPLATE_NAME_PATH", TEMPLATE_NAME);
?>

<?php
	//include("module/controller/rate/get-rate.php");
	$WPath = FOLDER_HOST;	
	$document = new document($db, $smarty);
	$page = '';
	$cat = '';
	$product = '';
	
	if ($WPath == '/') {
			$url = substr($_SERVER['REQUEST_URI'],1);
	} else {
			$url = preg_replace($WPath,"", $_SERVER['REQUEST_URI'],1);
			$url=explode("?",$url);
		
			$url = str_replace('//',"", $url[0]);
	}
	$url_array=explode("/",$url);
	//var_dump($url);
	$page = $url_array[0];
	
	$cat = $document->khongdau($url_array[1]);
	$product = $document->khongdau($url_array[2]);
	$smarty->assign('WPATH',$WPath);
	$listcat = new category($db, $smarty,$WPath);
	$listcat->view_top_category();
	$_REQUEST['page']=$page;
	//include("module/controller/JKlistcounter.php");
	$config = new config($db, $smarty);
	$config->process();
	
	
	
	$page_op = $document->RewriteLinkToFile($page);
	
	$document->WritePath($WPath,$page,$cat,$product);
	if(isset($_POST['pagesearch']) && $_POST['pagesearch'] == 'search'){
		require_once("module/controller/page.class.php");
		$search = new page($db, $smarty,$page,$cat,$product);	
		$search->searchpage();	
	}else{
		
		$option = "";
		if($option==""){
			$option = $page_op;
		}
		if (file_exists("module/controller/".$option.".class.php")){
			include_once("module/controller/".$option.".class.php");
			// we render html depend on parameter
			if($option != ""){
				//we use @ sign to ignore error and do not show any thing
				@($$option = new $option($db, $smarty,$page,$cat,$product));
				$$option->main();
			}
		}
	}
	//Show page
	
	
ob_end_flush();	
?>